/*

Copyright (C) 2007 Thomas Geiger (tom.geiger@gmail.com)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

#ifndef XIOCLIENT_H_
#define XIOCLIENT_H_

#include <iostream>
#include <sstream>

#include <globus_xio.h>
#include <globus_xio_gridftp_driver.h>
#include <globus_xio_http.h>
#include <globus_xio_gssapi_ftp.h>
#include <globus_xio_system.h>
#include <globus_common.h>

// security
#include <globus_xio_gsi.h>
#include <globus_gss_assist.h>

#include "URL.h"

namespace globus_xio {

using namespace globus_common;

static const int BUF_SIZE = 256;

/**
 * XIOClient supports file transfer operations using the XIO module.
 * Supported protocols are:
 * - local (file:///)
 * - GASS (http://, https://)
 * - GridFTP (ftp://, gsiftp://)
 */
class XIOClient
{
	private:
		URL* 			url;
	    globus_xio_stack_t  stack;
	    globus_xio_driver_t driver;
	    globus_xio_attr_t   attr;    
	    globus_xio_handle_t handle;	
	    bool				error;
	    gss_cred_id_t credential_handle;
	    void test_error(globus_result_t res, int line);	
	protected:
		/**
		 * Populate XIO stack according to the specified URL
		 */
		void initDriver(URL*);
	public:
		/**
		 * Constructor
		 */
		XIOClient();
		/**
		 * Destructor
		 */
		virtual ~XIOClient();
		/**
		 * Receive data from a stream
		 */
		bool receive(ostream&);
		/**
		 * Send data to a stream
		 */
		bool send(istream&);
		/**
		 * Set target/destination URL
		 */
		void setUrl(URL*);
		/**
		 * Returns the current URL
		 */
		URL* getUrl();
};

}

#endif /*GLOBUSXIOCLIENT_H_*/
